home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / gfx / show / JPEGv42source.lha / GC / JPEG / jrdmultipic.c < prev    next >
C/C++ Source or Header  |  1993-06-05  |  3KB  |  125 lines

  1.  
  2. /*
  3.  * jrdmultipic.c
  4.  *
  5.  * by Lutz Vieweg 1993
  6.  *
  7.  * based on code by
  8.  *
  9.  * Thomas G. Lane.
  10.  */
  11.  
  12. #include "jinclude.h"
  13.  
  14. #undef GLOBAL
  15.  
  16. #include <inline/exec.h>
  17. #include <exec/libraries.h>
  18. #include <dos/dos.h>
  19.  
  20. #define C_ONLY
  21. #include <inline/mpic.h>
  22.  
  23.  
  24. static struct PicHandle * phan = 0;
  25. static struct PicInfo * pinf = 0;
  26. struct Library * MultiPicBase = 0;
  27.  
  28. /* This version is for reading 8-bit, not implemented yet
  29.  
  30. METHODDEF void
  31. get_text_gray_row (compress_info_ptr cinfo, JSAMPARRAY pixel_row)
  32. {
  33.   register JSAMPROW ptr0;
  34.   register unsigned int val;
  35.   register long col;
  36.   
  37.   ptr0 = pixel_row[0];
  38.   for (col = cinfo->image_width; col > 0; col--) {
  39.     val = read_pbm_integer(cinfo);
  40.     if (rescale != NULL)
  41.       val = rescale[val];
  42.     *ptr0++ = (JSAMPLE) val;
  43.   }
  44. }
  45.  
  46. */
  47.  
  48.  
  49. METHODDEF void
  50. get_rgb_row (compress_info_ptr cinfo, JSAMPARRAY pixel_row)
  51. /* This version is for reading 24-bit files */
  52. {
  53.   MP_Read(phan, pixel_row[0], pixel_row[1], pixel_row[2], 0, 1);
  54.   
  55. }
  56.  
  57.  
  58. static void clrmpic(void) {
  59.     
  60.     if (phan) MP_Close(phan);
  61.     if (MultiPicBase) CloseLibrary(MultiPicBase);
  62.     
  63. }
  64.  
  65. /*
  66.  * Read the file header; return image size and component count.
  67.  */
  68.  
  69. METHODDEF void
  70. input_init (compress_info_ptr cinfo)
  71. {
  72.   long tags[] = {
  73.       
  74.       BAT_Flags, BAF_MERGEPALETTE,
  75.       TAG_DONE
  76.       
  77.   };
  78.   atexit(clrmpic);
  79.   if (0 == (MultiPicBase = OpenLibrary( "multipic.library", 0 ))) ERREXIT(cinfo->emethods, "unable to open multipic.library");
  80.   
  81.   phan = MP_Open( (unsigned char *)cinfo->input_file, 0);
  82.   if (phan == 0)  ERREXIT(cinfo->emethods, "input picture unavailable or of unknown format");
  83.   pinf = MP_Info (phan);
  84.   if (pinf == 0)  ERREXIT(cinfo->emethods, "input picture unavailable or of unknown format");
  85.  
  86.   if (!MP_SetBufferAttrs(phan, (struct TagItem *) tags)) ERREXIT(cinfo->emethods, "input picture unavailable or of unknown format");
  87.  
  88.   cinfo->methods->get_input_row = get_rgb_row;
  89.   cinfo->input_components = 3;
  90.   cinfo->in_color_space = CS_RGB;
  91.  
  92.   cinfo->image_width = pinf->pi_Width;
  93.   cinfo->image_height = pinf->pi_Height;
  94.   cinfo->data_precision = BITS_IN_JSAMPLE;
  95.  
  96. }
  97.  
  98. /*
  99.  * Finish up at the end of the file.
  100.  */
  101.  
  102. METHODDEF void
  103. input_term (compress_info_ptr cinfo)
  104. {
  105.   /* wird automatisch erledigt */
  106. }
  107.  
  108.  
  109. /*
  110.  * The method selection routine for PPM format input.
  111.  * Note that this must be called by the user interface before calling
  112.  * jpeg_compress.  If multiple input formats are supported, the
  113.  * user interface is responsible for discovering the file format and
  114.  * calling the appropriate method selection routine.
  115.  */
  116.  
  117. GLOBAL void
  118. jselmultipic (compress_info_ptr cinfo)
  119. {
  120.   cinfo->methods->input_init = input_init;
  121.   /* cinfo->methods->get_input_row is set by input_init */
  122.   cinfo->methods->input_term = input_term;
  123. }
  124.  
  125.